package com.hspedu.homework.Homework01;

/**
 * @author DL5O
 * @version 1.0
 */
public class EcmDef {
    public static void main(String[] args) {
        int num1 = 0;
        int num2 = 0;
        try {
             if(args.length != 2){
                throw new ArrayIndexOutOfBoundsException("参数个数不对");
            }
            num1 = Integer.parseInt(args[0]);
            num2 = Integer.parseInt(args[1]);
            int ret = cal(num1,num2);
        }catch (ArithmeticException e){
            System.out.println("算术异常");
        }
        catch(ArrayIndexOutOfBoundsException e){
            System.out.println("缺少命令行参数");
        } catch (NumberFormatException e) {
            System.out.println("数据格式异常");
        }

       /* try {
            //先验证输入的两个参数是否正确
            if(args.length != 2){
                throw new ArrayIndexOutOfBoundsException("参数个数不对");
            }
            int num1 = Integer.parseInt(args[0]);
            int num2 = Integer.parseInt(args[1]);
            //把接收到的字符串，转换为整数

            double res = cal(num1,num2);//该方法可能抛出ArithmeticException
            System.out.println("计算结果=" + res);
        }catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (NumberFormatException e){
            System.out.println("参数格式不正确，需要输入整数");
        }catch(ArithmeticException e){
            System.out.println("出现了除0的异常..");
        }*/


    }

    public static int cal(int num1 , int num2){
        try {
            return num1/num2;
        } catch (ArithmeticException e) {
            System.out.println("除数不能为0");
        }
        return num1/num2;
    }
}


